package org.example.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.entity.WeatherStation;
import org.example.mapper.WeatherStationMapper;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class StationManager extends ServiceImpl<WeatherStationMapper, WeatherStation> {
    private final WeatherStationMapper weatherStationMapper;

    public StationManager(WeatherStationMapper weatherStationMapper) {
        this.weatherStationMapper = weatherStationMapper;
    }

    public Long selectByCode(String code) {
        WeatherStation weatherStation = weatherStationMapper.selectOne(Wrappers.<WeatherStation>lambdaQuery().eq(WeatherStation::getCode, code));
        if (Objects.nonNull(weatherStation)){
            return weatherStation.getId();
        }
        return 0L;
    }
}
